<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>简单的表单提交</title>
</head>
<body>
	<form method="post" action="handle.php" id="formtest">
		Name: <input type="text" name="fname" id="fname">
		<br>
		Age: <input type="text" name="fage" id="fage">
		<br>
		<button onclick="ClickSubmit()" type="button">提交</button>
	</form>
	<script type="text/javascript">
		//判断提交的内容是否为空
		function check(){
			var UserName = document.getElementById("fname").value;
			var UserAge = document.getElementById("fage").value;
			if(UserName == null || UserName == ''){
				alert("用户名不能为空");
				return false;
			}
			if(UserAge == null || UserAge == ''){
				alert("年龄不能为空");
				return false;
			}
			return true;
		}
		//提交表单
		function ClickSubmit(){
			if(check()){
				document.getElementById("formtest").submit();
			}
		}
	</script>
</body>
</html>